'''
该文件为导弹实体,记录攻击过程
'''
import math
import numpy as np
import copy

class Missile:
    def __init__(self,发射回合,D_W,vehicle_position,target_position):
        '''
        创建实体
        :param 发射回合:
        :param 倒计时:
        :param D_W
        '''
        #self.Att_from=从哪来
        #self.Att_to=到哪去
        self.D_W=D_W    # 0 f , 1 e
        self.current_round=发射回合
        self.att_countdown=1
        self.命中结果=0
        self.activity=1
        self.Position = vehicle_position[:]     # 只保留值
        self.target_position=target_position
        self.speed=0.5
        self.post_epidoses=0
        # 记录导弹的所有坐标
        self.position_memo = []
        self.max_hight=3.8


    '''导弹倒计时更新'''
    # def countdown(self):
    #     if self.att_countdown>-1:
    #         self.att_countdown-=1

    def fly(self,dt):
        dis = self.distance_xyz(self.Position, self.target_position)
        # print(self.Position)
        # 添加导弹坐标到导弹坐标记忆中
        copy_pos = copy.deepcopy(self.Position)
        self.position_memo.append(copy_pos)

        if dis<(self.speed*dt):
            self.Position=self.target_position[:]
            self.att_countdown=0
        else:
            diff_position=np.array(self.target_position)-np.array(self.Position)
            aug_position=diff_position*(self.speed*dt/dis)
            self.Position=list(aug_position+self.Position)
            self.post_epidoses+=1

    def distance_xyz(self,A,B):
        x=B[0]-A[0]
        y = B[1] - A[1]
        z = B[2] - A[2]
        dis=math.sqrt(x**2+y**2+z**2)
        return dis










